package material.encapsulation_algorithm.hook;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class TeaWithHook extends CaffeinBeverageWithHook {
    @Override
    void brew() {
        System.out.println("将茶叶放入沸水中");
    }

    @Override
    void addCondiments() {
        System.out.println("加入柠檬");
    }

    /**
     * 让用户输入他们对调料的决定，根据用户的输入返回true或false
     *
     * @return
     */
    @Override
    public boolean customWantsCondiments() {
        String answer = getUserInput();
        if (answer.toLowerCase().startsWith("y")) {
            return true;
        } else {
            return false;
        }
    }

    private String getUserInput() {
        String answer = null;
        System.out.println("您需要茶里面加柠檬吗？");
        InputStream in;
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        try {
            answer = input.readLine();
        } catch (IOException ioe) {
            System.out.println("IO error tring to read your answer");
        }
        if (answer == null) {
            return "no";
        }
        return answer;
    }
}
